package com.bookstore.controller;

import com.bookstore.model.Seller;
import com.bookstore.service.SellerBookManagementService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class SellerBookManagementController {
    @Resource
    private SellerBookManagementService sellerBookManagementService;

    @RequestMapping(value = "/seller")
    public String view(){
        return "SellerBookManagement";
    }

    //查所有
    @RequestMapping(value = "/findSeller")
    public ModelAndView findSeller(Seller seller){
        ModelAndView mv = new ModelAndView("SellerBookManagement");
        List<Seller> sellers = sellerBookManagementService.findSeller(seller);
        mv.addObject("sellers",sellers);
        return mv;
    }

    //根据类型查询
    @RequestMapping(value = "/kind")
    public ModelAndView kind(Seller seller){
        ModelAndView mv = new ModelAndView("SellerBookManagement");
        List<Seller> sellers = sellerBookManagementService.kind(seller);
        mv.addObject("sellers",sellers);
        return mv;
    }

    //根据书名的模糊查询
    @RequestMapping(value = "/findBookName")
    public ModelAndView findBookName(Seller seller){
        ModelAndView mv = new ModelAndView("SellerBookManagement");
        List<Seller> sellers = sellerBookManagementService.findBookName(seller);
        mv.addObject("sellers",sellers);
        return mv;
    }


    //修改
    @RequestMapping(value = "/update")
    public ModelAndView update(Seller seller){
        ModelAndView mv = new ModelAndView("SellerBookManagement");
        List<Seller> sellers = sellerBookManagementService.findSeller(seller);
        sellerBookManagementService.update(seller);
        mv.addObject("sellers",sellers);
        return mv;
    }

}
